<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>call / apply</title>
</head>
<body>

</body>
<script>
    // call 改变this指向
    // call 需要把实参按照形参的个数传进去
    function Person(name, age) {
        this.name = name;
        this.age = age;
    }
    var person = new Person('fan', 18);
    var obj = {}
    Person.call(obj, 'hflxhn', 20);

    // 例子
    function Wheel(wheelSize, style) {
        this.wheelSize = wheelSize;
        this.style = style;
    }
    function Sit(c, sitColor) {
        this.c = c;
        this.sitColor = sitColor;
    }
    function Model(height, width, len) {
        this.height = height;
        this.width = width;
        this.len = len;
    }
    function Car(wheelSize, style, c, sitColor, height, width, len) {
        Wheel.call(this, wheelSize, style);
        Sit.call(this, c, sitColor);
        Model.call(this, height, width, len);
    }
    var car = new Car(100, '花里胡哨', '真皮', 'red', 1800, 1900, 4900);

    // apply 需要传一个 arguments
    function Car1(wheelSize, style, c, sitColor, height, width, len) {
        Wheel.apply(this, [wheelSize, style]);
        Sit.apply(this, [c, sitColor]);
        Model.apply(this, [height, width, len]);
    }
    var car1 = new Car1(100, '花里胡哨', '真皮', 'red', 1800, 1900, 4900);
</script>
</html>
